<!--
 * @Author: sbotlp
 * @Email: sbotlp@sina.com
 * @Date: 2019-11-17 15:26:24
 * @LastEditTime: 2019-11-17 16:01:37
 * @Description: http://www.sbotlp.com.cn
 -->
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  async-await test
  <script>
      function loadImage(src) {
      const proimse = new Promise((resolve, reject) => {
        const img = document.createElement('img');
        img.src = src;
        img.onload=function() {
          resolve(img);
        }
        img.onerror=function(error) {
          reject('图片加载失败');
        }
        // throw new Error('自定义报错');
      })
      return proimse;
    };
    const src1 = `https://api.sbotlp.com.cn/public/image/20191106/1573030513.png`;
    const src2 = `https://api.sbotlp.com.cn/public/image/20190924/1569308973.png`;
    const load = async function () {
      const result1 = await loadImage(src1);
      console.log('result1: ', result1);
      const result2 = await loadImage(src2);
      console.log('result2: ', result2);
    };
    load();
    /* 
      async-await 使用了Promise 封装，并没有和Promise冲突；
      完全是同步写法，再也没回调函数；
      但是改变不了js是单线程、异步执行的本质，
    */
  </script>
</body>
</html>